import {
  getImformationList,
  getHotImformationList,
  getImformationInfo,
  getReadingList
} from "@/assets/api/InformationApi";


export const state = () => ({

  shouyeList: [],
  indexList: [],

  dataInfo: {},


  tabsList: [{
      id: 0,
      name: "热门资讯",
      pathName: 'rmzx',
      weigh: 0,
    },
    {
      id: 3,
      name: "财政资讯",
      pathName: 'czzx',
      weigh: 10,
    },
    {
      id: 1,
      name: "考试资讯",
      pathName: 'kszx',
      weigh: 9,
    },
    {
      id: 2,
      name: "税局稽查",
      pathName: 'sjjc',
      weigh: 8,
    },
    {
      id: 4,
      name: "财税分享",
      pathName: 'ggwz',
      weigh: 0,
    },
  ],

  ReadingList: []

})

export const getters = {
  shouyeList: state => state.shouyeList,
  indexList: state => state.indexList,
  dataInfo: state => state.dataInfo,
  tabsList: state => state.tabsList,
}

export const mutations = {

  set_shouyeList(state, data) {
    state.shouyeList = data;
  },
  set_indexList(state, data) {
    state.indexList = data;
  },
  set_dataInfo(state, data) {
    state.dataInfo = data;
  },
  set_ReadingList(state, data) {
    state.ReadingList = data;
  },
}

export const actions = {
  async init({
    commit,
    state
  }, params2) {
    let params = {}
    if (params2.type) {
      params.tid = state.tabsList[params2.type].id
    } else {
      params.is_shouye = 1
    }
    params.page = params2.page ? params2.page : 1
    const res = await getImformationList(params);
    if (res.code == 1)
      commit('set_shouyeList', res.data)
    const res2 = await getHotImformationList({
      page: params2.page ? params2.page : 1,
      pageSize: 20,
    });

    if (res2.code == 1) {
      commit('set_indexList', res2.data)
    }
    const res3 = await getReadingList({});
    if (res3.code == 1) {
      commit('set_ReadingList', res3)
    }

  },

  async infoInit({
    commit,
    state
  }, params) {
    const res = await getImformationInfo(params)
    if (res.code == 1) {
      commit('set_dataInfo', res.data)
    }

    const res3 = await getReadingList({});
    if (res3.code == 1) {
      commit('set_ReadingList', res3)
    }

  }



}
